using UnityEngine;
using UnityEngine.UI;

namespace Utils.Extends
{
    public static class ColorExtends
    {
        public static Color SetR(this Color color, float r)
        {
            color.r = r;
            return color;
        }

        public static Color SetG(this Color color, float g)
        {
            color.g = g;
            return color;
        }

        public static Color SetB(this Color color, float b)
        {
            color.b = b;
            return color;
        }

        public static Color SetA(this Color color, float a)
        {
            color.a = a;
            return color;
        }
        
        /// <summary>
        /// 设置Graphic的透明度
        /// </summary>
        /// <param name="target"> Graphic </param>
        /// <param name="a"> 透明度 </param>
        public static void SetAlpha(this Graphic target, float a)
        {
            Color color = target.color;
            color.a = a;
            target.color = color;
        }

        public static void SetAlpha(this Material target, string property, float a)
        {
            Color color = target.GetColor(property);
            color.a = a;
            target.SetColor(property, color);
        }
    }
}
